package com.his.dictcode.service.Imp;

import com.his.dictcode.dao.DictCodeTypeMapper;
import com.his.dictcode.entity.DictCodeType;
import com.his.dictcode.service.DictCodeTypeService;
import com.his.dictcode.vo.DictCodeTypeVo;
import com.xiao.common.exception.HisExecption;
import com.xiao.common.util.BeanUtil;
import com.xiao.common.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author changlong
 * @date 2020/2/4 0004 - 17:26
 */

/**
 * Vo里需要的字段最好跟实体里的字段一致 这样就可以用Beantuil这个工具进行复制
 */
@Service
public class DictCodeTypeServiceImpl implements DictCodeTypeService {
    @Autowired
    private DictCodeTypeMapper dictCodeTypeMapper;

    @Override
    public List<DictCodeType> queryAll(String keyWords){
        DictCodeType dictCodeType = new DictCodeType();
        dictCodeType.setCODETYPEID(keyWords);
        List<DictCodeType> dictCodeTypes = dictCodeTypeMapper.selectByEntity(dictCodeType);
        return dictCodeTypes;
    }

    @Override
    public void insertAll(DictCodeTypeVo dictCodeTypeVo){
        DictCodeType dictCodeType = BeanUtil.copyBean(dictCodeTypeVo,DictCodeType.class);
        List<DictCodeType> list = dictCodeTypeMapper.selectByEntity(dictCodeType);
        if(list.size()>0){
            throw HisExecption.serverErrException("基础编码类型已存在！");
        }
        dictCodeTypeMapper.insertALlColumn(dictCodeType);
    }

    @Override
    public void updateById(DictCodeTypeVo dictCodeTypeVo){
        DictCodeType dictCodeType = BeanUtil.copyBean(dictCodeTypeVo,DictCodeType.class);
        dictCodeTypeMapper.updateById(dictCodeType);
    }

    @Override
    public void deleteById(DictCodeTypeVo dictCodeTypeVo){
        DictCodeType dictCodeType = BeanUtil.copyBean(dictCodeTypeVo,DictCodeType.class);
        dictCodeTypeMapper.deleteById(dictCodeType);
    }

    @Override
    public DictCodeType selectById(String codeTypeId) {
        return dictCodeTypeMapper.selectById(codeTypeId);
    }
}
